package com.ryan.day06;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * 实现选择排序
 */
public class SelectSort {
    public static void main(String[] args) {
        int[] arr = {15,102,596,62,308,1,553,964,552,719,55,669,275,65,806,888,134,922,253,49,774,259,786,492,553,217,673,979,837,475,362,400,774,496,156,133,659,183,546,51,482,934,455,785,50,85,429,496,5};
        selectSort(arr);
    }


    public static void selectSort(int[] arr) {

        for (int i = 0;i<arr.length-1;i++){
            int minIndex = i;
            int min = arr[i];
            for (int j= i+1;j<arr.length;j++){
                if(min>arr[j]){
                    min = arr[j];
                    minIndex = j;
                }
            }
            arr[minIndex] = arr[i];
            arr[i]= min;
        }
            System.out.println(Arrays.toString(arr));
    }
}